<!-- 样式 -->
<style>
  .import {
    opacity: 0;
    position: absolute;
    width: 69px;
    height: 38px;
    margin-left: -10px;
  }
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <!-- 头部操作栏 -->
      <div class="layui-form lay-header">
        <div class="toolbar">
          <div class="layui-form-item lay-query-content">
            <div class="lay-query-box">
              <div class="query-lt">
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">节点编码：</label>
                  <div class="layui-input-inline">
                    <input name="code" class="layui-input" type="text" placeholder="请输入节点编码" autocomplete="off" />
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">节点名称：</label>
                  <div class="layui-input-inline">
                    <input name="name" class="layui-input" type="text" placeholder="请输入节点名称" autocomplete="off" />
                  </div>
                </div>
                <div class="layui-inline">
                  <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit layui-form-keyDownSearch="true">查询</button>
                  <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                </div>
              </div>
              <div class="query-rt"></div>
            </div>
          </div>
        </div>
        <div class="lay-btn-rows">
          <div class="lay-btn-box">
            <div class="lay-btn-lt">
              <button id="processInfoBtnAdd" class="layui-btn icon-btn color-reseda">添加</button>
              <button id="confirmSelect" class="layui-btn icon-btn color-reseda" style="display: none">确认选择</button>
            </div>
            <div class="lay-btn-rt">
              <button id="downloadTemplate" class="layui-btn icon-btn color-green">下载模版</button>
              <button class="layui-btn icon-btn color-reseda"><input id="uploaderInput" type="file" name="file" class="import" accept=".xls,.xlsx" />导入</button>
            </div>
          </div>
        </div>
      </div>
      <!-- 表格 -->
      <table class="layui-table" id="processInfoTable" lay-filter="processInfoTable"></table>
    </div>
  </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="processInfoTableBar">
  <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">修改</a>
  <a class="layui-btn layui-btn layui-btn-xs" lay-event="processItem">检测项管理</a>
  <a class="layui-btn layui-btn layui-btn-xs" lay-event="processException">质检异常设置</a>
  <a class="layui-btn layui-btn layui-btn-xs" lay-event="processDevice">工序设备管理</a>
  <!--    <a class="layui-btn layui-btn-xs" lay-event="processQuality">质检参数设置</a>-->
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="processInfoForm">
  <form lay-filter="processInfoForm" class="layui-form model-form">
    <input name="id" type="hidden" />

    <div class="layui-form-item">
      <div class="layui-col-md6">
        <label class="layui-form-label" style="width: 100px">节点类型</label>
        <div class="layui-input-block" style="margin-left: 130px; width: 70%">
          <select id="nodeTypes" name="nodeTypes" lay-filter="nodeTypes" lay-search lay-verify="required"></select>
        </div>
      </div>
      <div class="layui-col-md6">
        <label class="layui-form-label" style="width: 100px">工序性质</label>
        <div class="layui-input-block" style="margin-left: 130px; width: 70%">
          <select id="processNature" name="processNature" lay-filter="processNature" lay-search lay-verify="required"></select>
        </div>
      </div>
    </div>

    <div class="layui-form-item">
      <div class="layui-col-md6">
        <label class="layui-form-label" style="width: 100px">节点名称</label>
        <div class="layui-input-block" style="margin-left: 130px; width: 70%">
          <input name="nodeNames" placeholder="请输入节点名称" type="text" class="layui-input" lay-verify="required" required autocomplete="off" />
        </div>
      </div>
      <div class="layui-col-md6">
        <label class="layui-form-label" style="width: 100px">节点编码</label>
        <div class="layui-input-block" style="margin-left: 130px; width: 70%">
          <input name="nodeCodes" placeholder="请输入节点编码" type="text" class="layui-input" lay-verify="required" required autocomplete="off" />
        </div>
      </div>
    </div>

    <div class="layui-form-item">
      <div class="layui-col-md6">
        <label class="layui-form-label" style="width: 100px">是否支持委外</label>
        <div class="layui-input-block" style="margin-left: 130px; width: 70%">
          <select id="isOutsource" name="isOutsource" lay-filter="isOutsource" lay-search lay-verify="required"></select>
        </div>
      </div>
      <div class="layui-col-md6">
        <label class="layui-form-label" style="width: 100px">报工单位</label>
        <div class="layui-input-block" style="margin-left: 130px; width: 70%">
          <input name="unitId" placeholder="请输入报工单位" type="text" class="layui-input" />
        </div>
      </div>

      <!-- <div class="layui-col-md6">
        <label class="layui-form-label" style="width: 100px"
          >是否用刀工序</label
        >
        <div class="layui-input-block" style="margin-left: 130px; width: 70%">
          <select
            id="isUseknifeProcess"
            name="isUseknifeProcess"
            lay-filter="isUseknifeProcess"
            lay-search
            lay-verify="required"
          ></select>
        </div>
      </div> -->
    </div>

    <div class="layui-form-item">
      <div class="layui-col-md6">
        <label class="layui-form-label" style="width: 100px">状态</label>
        <div class="layui-input-block" style="margin-left: 130px; width: 70%">
          <select id="status" name="status"></select>
        </div>
      </div>
      <div class="layui-col-md6">
        <label class="layui-form-label" style="width: 100px">排序</label>
        <div class="layui-input-block" style="margin-left: 130px; width: 70%">
          <input name="sortNumber" placeholder="请输入排序" type="text" class="layui-input" pattern="\d*" oninput="this.value=this.value.replace(/\D/g,'')" autocomplete="off" />
        </div>
      </div>
    </div>

    <div class="layui-form-item">
      <div class="layui-col-md6">
        <label class="layui-form-label" style="width: 100px">工种</label>
        <div class="layui-input-block" style="margin-left: 130px; width: 70%">
          <select id="personnelWorkType" lay-filter="personnelWorkType" name="personnelWorkType"></select>
        </div>
      </div>
      <div class="layui-col-md6">
        <label class="layui-form-label" style="width: 100px">备注</label>
        <div class="layui-input-block" style="margin-left: 130px; width: 70%">
          <input name="remark" placeholder="请输入备注" type="text" class="layui-input" lay-verify="" required />
        </div>
      </div>
    </div>

    <div class="site-border-green">
      <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend class="layui-font-green" style="font-size: 16px;">是否创建物资类别</legend>
      </fieldset>
    </div>

    <div class="layui-form-item">
      <div class="layui-col-md6">
        <label class="layui-form-label" style="width: 100px">生成物资类别</label>
        <div class="layui-input-block" style="margin-left: 130px; width: 70%">
          <select id="productTypeIf" name="productTypeIf" lay-filter="productTypeIf" lay-search lay-verify="required"></select>
        </div>
      </div>
      <div class="layui-col-md6" id="productTypeDiv" style="display: none">
        <label class="layui-form-label" style="width: 100px">物资类别</label>
        <input name="productTypeId" type="hidden" />
        <div class="layui-input-block" id="selectProductType" style="margin-left: 130px; width: 70%"></div>
      </div>
      <div class="layui-col-md6" id="productTypeNatureDiv">
        <label class="layui-form-label" style="width: 100px">物料类别性质</label>
        <div class="layui-input-block" style="margin-left: 130px; width: 70%">
          <select id="productTypeNature" name="productTypeNature" lay-filter="productTypeNature" lay-search></select>
        </div>
      </div>
    </div>

    <div class="layui-form-item">
      <div class="layui-col-md6" id="parentProductTypeDiv">
        <label class="layui-form-label" style="width: 100px">所属物资类别</label>
        <input name="parentProductType" type="hidden" />
        <div class="layui-input-block" id="selectParentProductType" style="margin-left: 130px; width: 70%"></div>
      </div>
      <div class="layui-col-md6" id="typeServiceDepartmentDiv">
        <label class="layui-form-label" style="width: 100px">类别维护部门</label>
        <input name="typeServiceDepartment" type="hidden" />
        <div class="layui-input-block" id="selectDepartment" style="margin-left: 130px; width: 70%"></div>
      </div>
    </div>

    <div class="site-border-green">
      <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend class="layui-font-green" style="font-size: 16px;">如果需要质检，则该工序支持关联工序模板</legend>
      </fieldset>
    </div>

    <div class="layui-form-item">
      <div class="layui-col-md6">
        <label class="layui-form-label" style="width: 100px">是否需要质检</label>
        <div class="layui-input-block" style="margin-left: 130px; width: 70%">
          <select id="qualityIf" name="qualityIf" lay-filter="qualityIf" lay-search lay-verify="required"></select>
        </div>
      </div>
      <div class="layui-col-md6" id="qualityRateDiv">
        <label class="layui-form-label" style="width: 100px">质检属性</label>
        <div class="layui-input-block" style="margin-left: 130px; width: 70%">
          <select id="qualityAttributes" name="qualityAttributes" lay-filter="qualityAttributes" lay-search>
            <option value="1">一物一检</option>
            <option value="2">简易检测</option>
          </select>
        </div>
      </div>

      <!-- <div class="layui-col-md6" id="qualityRateDiv">
        <label class="layui-form-label" style="width: 100px">检验频率</label>
        <div class="layui-input-block" style="margin-left: 130px; width: 70%">
          <select
            id="qualityRate"
            name="qualityRate"
            lay-filter="qualityRate"
            lay-search
          ></select>
        </div>
      </div> -->
    </div>

    <div class="site-border-green">
      <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend class="layui-font-green" style="font-size: 16px;">以下为创建工序对应工序仓的设置</legend>
      </fieldset>
    </div>

    <div class="layui-form-item">
      <div class="layui-col-md6">
        <label class="layui-form-label" style="width: 100px">创建工序仓</label>
        <div class="layui-input-block" style="margin-left: 130px; width: 70%">
          <select id="processWarehouseIf" name="processWarehouseIf" lay-filter="processWarehouseIf" lay-search lay-verify="required"></select>
        </div>
      </div>
      <div class="layui-col-md6" id="thingCodeStatusDiv">
        <label class="layui-form-label" style="width: 100px">是否一物一码</label>
        <div class="layui-input-block" style="margin-left: 130px; width: 70%">
          <select id="thingCodeStatus" name="thingCodeStatus" lay-filter="thingCodeStatus" lay-search></select>
        </div>
      </div>
    </div>

    <div class="layui-form-item">
      <div class="layui-col-md6" id="guaranteeStatusDiv">
        <label class="layui-form-label" style="width: 100px">是否有质保期</label>
        <div class="layui-input-block" style="margin-left: 130px; width: 70%">
          <select id="guaranteeStatus" name="guaranteeStatus" lay-filter="guaranteeStatus" lay-search></select>
        </div>
      </div>
      <div class="layui-col-md6" id="inoutStatusDiv">
        <label class="layui-form-label" style="width: 100px">是否先进先出</label>
        <div class="layui-input-block" style="margin-left: 130px; width: 70%">
          <select id="inoutStatus" name="inoutStatus" lay-filter="inoutStatus" lay-search></select>
        </div>
      </div>
    </div>

    <div class="layui-form-item text-right">
      <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
      <button class="layui-btn" lay-filter="processInfoFormSubmit" lay-submit>保存</button>
    </div>
  </form>
</script>

<script type="text/html" id="processDeviceForm">
  <div class="layui-form open-form">
    <div class="open-model">
      <div class="open-auto">
        <div class="layui-form-item" style="margin-bottom: 5px;">
          <div class="layui-inline">
            <button id="processDeviceBtnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
            <button id="batchDelBtn" class="layui-btn icon-btn layui-btn-danger"><i class="layui-icon"></i>批量删除</button>
          </div>
        </div>
        <table class="layui-table" id="processDeviceTable" lay-filter="processDeviceTable"></table>
      </div>
      <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
      </div>
    </div>
  </div>
</script>
<!-- 表格操作列 -->
<script type="text/html" id="processDeviceTableBar">
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">移除</a>
</script>

<script type="text/html" id="deviceForm">
  <div class="layui-form open-form">
    <div class="open-model">
      <div class="open-auto" style="padding-top: 5px;">
        <table class="layui-table" id="deviceTable" lay-filter="deviceTable"></table>
      </div>
      <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="deviceTableSubmit" lay-submit>保存</button>
      </div>
    </div>
  </div>
</script>
<!-- 质检 -->
<script type="text/html" id="processQualityForm">
  <div style="padding: 20px;">
    <div class="layui-form toolbar">
      <div class="layui-form-item">
        <div class="layui-inline">
          <button id="processQualityBtnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
          <button id="processQualityBtnExport" class="layui-btn icon-btn"><i class="layui-icon">&#xe67d;</i>导出</button>
        </div>
      </div>
    </div>
    <!-- 表格 -->
    <table class="layui-table" id="processQualityTable" lay-filter="processQualityTable"></table>
  </div>
</script>
<!-- 表格操作列 -->
<script type="text/html" id="processQualityTableBar">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!-- 表单弹窗 -->
<script type="text/html" id="processQualityAddForm">
  <form lay-filter="processQualityForm" class="layui-form model-form">
    <input name="id" type="hidden" />

    <div class="layui-form-item">
      <label class="layui-form-label">工序</label>
      <div class="layui-input-block">
        <select name="processId" id="processId" lay-verify="required" required>
          .
          <option value="">请选择</option>
        </select>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">参数分类</label>
      <input name="categoryId" type="hidden" />
      <div class="layui-input-block" id="selectCategory"></div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">参数名</label>
      <div class="layui-input-block">
        <input name="name" placeholder="请输入参数名" type="text" class="layui-input" lay-verify="required" required autocomplete="off" />
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">识别码</label>
      <div class="layui-input-block">
        <input name="code" placeholder="请输入识别码" type="text" class="layui-input" lay-verify="required" required autocomplete="off" />
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">展示类型</label>
      <div class="layui-input-block">
        <select name="type" id="type" lay-verify="required" required>
          .
          <option value="">请选择</option>
          <option value="1">单选</option>
          <option value="2">复选</option>
          <option value="3">输入框</option>
        </select>
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">是否启用</label>
      <div class="layui-input-block">
        <input name="deleted" type="checkbox" lay-skin="switch" value="1" checked="false" lay-text="启用|停用" />
      </div>
    </div>
    <div class="layui-form-item text-right">
      <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
      <button class="layui-btn" lay-filter="processQualityFormSubmit" lay-submit>保存</button>
    </div>
  </form>
</script>

<!-- 检测项目 -->
<script type="text/html" id="processItemForm">
  <div class="open-form">
    <div class="open-model">
      <div class="open-auto">
        <!-- 头部操作栏 -->
        <div class="layui-form toolbar">
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label w-auto">名称：</label>
              <div class="layui-input-inline mr0">
                <input name="name" class="layui-input" type="text" placeholder="请输入名称" />
              </div>
            </div>
            <div class="layui-inline">
              <button class="layui-btn icon-btn" lay-filter="processItemSearchBtn" lay-submit layui-form-keyDownSearch="true"><i class="layui-icon">&#xe615;</i>搜索</button>
              <button id="processItemBtnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加检测项目</button>
              <button id="processItemCategoryBtnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>检测项目分类</button>
            </div>
          </div>
        </div>
        <!-- 表格 -->
        <table class="layui-table" id="processItemTable" lay-filter="processItemTable"></table>
      </div>
      <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
      </div>
    </div>
  </div>
</script>

<script type="text/html" id="productItemForm">
  <form lay-filter="productItemForm" class="layui-form model-form" style="padding-top: 20px;">
    <input name="id" type="hidden" />
    <input name="processId" type="hidden" />
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 100px;">工序名称</label>
      <div class="layui-input-block" style="margin-left: 130px;">
        <input name="processName" class="layui-input" disabled />
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 100px;">物资类别</label>
      <div class="layui-input-block" style="margin-left: 130px;">
        <select id="productType" name="productType" lay-filter="productType" disabled></select>
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 100px;">物资性质</label>
      <div class="layui-input-block" style="margin-left: 130px;">
        <select id="productNature" name="productNature" lay-filter="productNature" disabled></select>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 100px;">检测项目分类</label>
      <div class="layui-input-block" style="margin-left: 130px;">
        <select id="itemCategoryId" name="itemCategoryId" lay-filter="itemCategoryId"></select>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 100px;">检测项目名称</label>
      <div class="layui-input-block" style="margin-left: 130px;">
        <input name="name" placeholder="请输入检测项目名称" type="text" class="layui-input" lay-verify="required" required />
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 100px;">检测项目代码</label>
      <div class="layui-input-block" style="margin-left: 130px;">
        <input name="code" placeholder="请输入检测项目代码" type="text" class="layui-input" lay-verify="required" required />
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 100px;">质检类型</label>
      <div class="layui-input-block" style="margin-left: 130px;">
        <select id="itemType" name="itemType"></select>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 100px;">质检方法</label>
      <div class="layui-input-block" style="margin-left: 130px;">
        <select id="qualityWayId" name="qualityWayId" lay-filter="importanceCode"></select>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 100px;">质检器具</label>
      <div class="layui-input-block" style="margin-left: 130px;">
        <select id="deviceModelSpuId" name="deviceModelSpuId" lay-filter="deviceModelSpuId"></select>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 100px;">重要程度</label>
      <div class="layui-input-block" style="margin-left: 130px;">
        <select id="importanceCode" name="importanceCode" lay-filter="importanceCode"></select>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">是否启用</label>
      <div class="layui-input-block">
        <select name="isDeleted" lay-verify="required">
          <option value="false" selected>启用</option>
          <option value="true">不启用</option>
        </select>
      </div>
    </div>
    <!--        <div class="layui-form-item">-->
    <!--            <label class="layui-form-label" style="width: 100px;">检测类型</label>-->
    <!--            <div class="layui-input-block" style="margin-left: 130px;">-->
    <!--                <select id="itemType" name="itemType" lay-filter="itemType"></select>-->
    <!--            </div>-->
    <!--        </div>-->

    <!-- <div class="layui-form-item">
      <label class="layui-form-label" style="width: 100px;">样式</label>
      <div class="layui-input-block" style="margin-left: 130px;">
        <select id="style" name="style" lay-filter="style"></select>
      </div>
    </div> -->

    <!-- <div class="layui-form-item">
      <label class="layui-form-label" style="width: 100px;">描述</label>
      <div class="layui-input-block" style="margin-left: 130px;">
        <textarea
          name="remark"
          placeholder="请输入描述"
          class="layui-textarea"
        />
      </div>
    </div> -->
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 100px;">重要程度</label>
      <div class="layui-input-block" style="margin-left: 130px;">
        <select id="style" name="style" lay-filter="style">
          <option value="">请选择</option>
          <option value="0">多选</option>
          <option value="1">单选</option>
          <option value="2" selected>文本</option>
        </select>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 100px;">描述</label>
      <div class="layui-input-block" style="margin-left: 130px;">
        <input name="remark" placeholder="请输入描述" type="text" class="layui-input" />
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 100px;">排序</label>
      <div class="layui-input-block" style="margin-left: 130px;">
        <input name="sort" placeholder="请输入排序" type="text" class="layui-input" lay-verify="" required />
      </div>
    </div>

    <div class="layui-form-item text-right">
      <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
      <button class="layui-btn" lay-filter="productItemFormSubmit" type="button" lay-submit>保存</button>
    </div>
  </form>
</script>

<script type="text/html" id="productItemCategoryForm">
  <form lay-filter="productItemCategoryForm" class="layui-form model-form">
    <input name="id" type="hidden" />

    <div class="layui-form-item">
      <label class="layui-form-label">物资类别</label>
      <input name="code" type="text" class="layui-input" disabled />
      <div class="layui-input-inline mr0" id="selectProductTypeQuery" style="width: 297px;"></div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">物资性质</label>
      <div class="layui-input-block">
        <select id="productNature" name="productNature" disabled></select>
      </div>
    </div>

    <!--        <div class="layui-form-item">-->
    <!--            <label class="layui-form-label">检测类型</label>-->
    <!--            <div class="layui-input-block">-->
    <!--                <select id="itemType" name="itemType" lay-search lay-verify="required"></select>-->
    <!--            </div>-->
    <!--        </div>-->

    <div class="layui-form-item">
      <label class="layui-form-label">编码</label>
      <div class="layui-input-block">
        <input name="code" placeholder="请输入编码" type="text" class="layui-input" lay-verify="required" required />
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">名称</label>
      <div class="layui-input-block">
        <input name="name" placeholder="请输入名称" type="text" class="layui-input" lay-verify="required" required />
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">排序</label>
      <div class="layui-input-block">
        <input name="sort" placeholder="请输入排序" type="text" class="layui-input" lay-verify="number" required />
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">备注</label>
      <div class="layui-input-block">
        <textarea id="remark" name="remark" placeholder="请输入备注" class="layui-textarea" />
      </div>
    </div>

    <div class="layui-form-item text-right">
      <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
      <button class="layui-btn" lay-filter="productItemCategoryFormSubmit" lay-submit>保存</button>
    </div>
  </form>
</script>

<script type="text/html" id="productItemTableBar">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="editItem">修改</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<!-- js部分 -->
<script>
  layui.use(["layer", "form", "table", "admin"], async function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var config = layui.config;
    var admin = layui.admin;
    var upload = layui.upload;
    let nowData = {};
    let where = {};
    if (typeof parentData !== "undefined") {
      nowData = { ...parentData };
      where = nowData.where;
    }
    if (nowData.eventName == "radio" || nowData.eventName == "checkbox") {
      $("#confirmSelect").show();
      $("#processInfoBtnAdd").hide();
    }
    // 渲染表格
    var insTb = table.render({
      elem: "#processInfoTable",
      url: config.base + "enterprise/product/admin/processInfo/list",
      where: { ...where },
      toolbar: true,
      defaultToolbar: ["filter"],
      page: true,
      cellMinWidth: 100,
      cols: [
        [
          { type: "radio", hide: nowData.eventName != "radio" },
          { type: "checkbox", hide: nowData.eventName != "checkbox" },
          { field: "nodeCodes", align: "center", title: "节点编码" },
          { field: "nodeNames", align: "center", title: "节点名称" },
          { field: "nodeTypesName", align: "center", title: "节点类型" },
          { field: "processNatureName", align: "center", title: "工序性质" },
          {
            field: "qualityIf",
            align: "center",
            title: "是否支持委外",
            templet: function (d) {
              return d.isOutsource === "0" ? "是" : "否";
            }
          },
          // { field: "qualityRateName", align: "center", title: "检验频率" },
          {
            field: "processWarehouseIf",
            align: "center",
            title: "创建工序仓",
            templet: function (d) {
              return d.processWarehouseIf === "0" ? "是" : "否";
            }
          },
          {
            field: "createTime",
            align: "center",
            title: "创建时间",
            width: 180
          },
          {
            align: "center",
            toolbar: "#processInfoTableBar",
            title: "操作",
            width: 430,
            fixed: "right"
          }
        ]
      ],
      done: function (res, curr, count) {}
    });

    // 工具条点击事件
    table.on("tool(processInfoTable)", function (obj) {
      var data = obj.data;
      if (obj.event === "edit") {
        //修改
        showEditModel(data);
      } else if (obj.event === "del") {
        // 删除
        doDelete(obj);
      } else if (obj.event === "processDevice") {
        showProcessDevice(data);
      } else if (obj.event === "processQuality") {
        showProcessQuality(data);
      } else if (obj.event === "processItem") {
        // 工序检测项
        showProcessItemModel(data);
      } else if (obj.event === "processException") {
        // 工序质检异常
        admin.formOpen({
          area: ["90%", "90%"],
          offset: "25px",
          title: "质检异常设备",
          path: 'components/product/processExceptionByprocessException.html',
          success: function () {
            parentData.data = data;
          }
        });
      }
    });

    //监听排序
    table.on("sort(processInfoTable)", function (obj) {
      table.reload("processInfoTable", {
        initSort: obj,
        where: {
          sort: obj.field,
          order: obj.type
        }
      });
    });

    // 搜索
    form.on("submit(formSubSearchLog)", function (data) {
      insTb.reload({ where: data.field, page: { curr: 1 } }, "data");
    });

    // 重置搜索
    form.on("submit(resets)", (data) => {
      insTb.reload({ where: admin.resetSearch(data.field), page: { curr: 1 } }, "data");
    });

    // 添加按钮点击事件
    $("#processInfoBtnAdd").click(function () {
      showEditModel();
    });

    $("#confirmSelect").click(function () {
      let list = table.checkStatus("processInfoTable").data;
      childData.list = list;
      layer.close(nowData.zindex);
    });

    // 显示编辑弹窗
    function showEditModel(data) {
      admin.open({
        type: 1,
        area: "1000px",
        title: data ? "修改工序节点" : "添加工序节点",
        content: $("#processInfoForm").html(),
        success: async function () {
          if (data) {
            if (data.productTypeIf == 1) {
              $("#productTypeDiv").show();
              $("#productTypeNatureDiv").hide();
              $("#parentProductTypeDiv").hide();
              $("#typeServiceDepartmentDiv").hide();
            } else {
              $("#productTypeDiv").hide();
              $("#productTypeNatureDiv").show();
              $("#parentProductTypeDiv").show();
              $("#typeServiceDepartmentDiv").show();
            }
            if (data.qualityIf == 1) {
              $("#qualityRateDiv").hide();
            } else {
              $("#qualityRateDiv").show();
            }
            if (data.processWarehouseIf == 1) {
              $("#thingCodeStatusDiv").hide();
              $("#guaranteeStatusDiv").hide();
              $("#inoutStatusDiv").hide();
            } else {
              $("#thingCodeStatusDiv").show();
              $("#guaranteeStatusDiv").show();
              $("#inoutStatusDiv").show();
            }
          } else {
            $("#productTypeDiv").show();
            $("#productTypeNatureDiv").hide();
            $("#parentProductTypeDiv").hide();
            $("#typeServiceDepartmentDiv").hide();
            $("#qualityRateDiv").hide();
            $("#thingCodeStatusDiv").hide();
            $("#guaranteeStatusDiv").hide();
            $("#inoutStatusDiv").hide();
          }
          //节点类型
          admin.getDictList("nodeTypes", "process_node_type", data ? data.nodeTypes : null, "节点类型");
          await admin.initDataSelectPro("production/productionPlan/admin/profession/list", {limit:99999}, "personnelWorkType", "人工工种", () => {}, "professionName");
          //工序性质
          admin.getDictList("processNature", "process_nature", data ? data.processNature : null, "工序性质");
          //是否支持委外
          admin.getDictList("isOutsource", "sys_yes_no", data ? data.isOutsource : null, "是否支持委外");
          //是否用刀工序
          // admin.getDictList(
          //   "isUseknifeProcess",
          //   "sys_yes_no",
          //   data ? data.isUseknifeProcess : null,
          //   "是否用刀工序"
          // );
          //状态
          admin.getDictList("status", "sys_status", data ? data.status : null, "状态");
          //生成物资类别
          admin.getDictList("productTypeIf", "sys_yes_no", data ? data.productTypeIf : 1, "生成物资类别");
          form.on("select(productTypeIf)", function (data) {
            if (data.value == 0) {
              $("#productTypeDiv").hide();
              $("#productTypeNatureDiv").show();
              $("#parentProductTypeDiv").show();
              $("#typeServiceDepartmentDiv").show();
            } else if (data.value == 1) {
              $("#productTypeDiv").show();
              $("#productTypeNatureDiv").hide();
              $("#parentProductTypeDiv").hide();
              $("#typeServiceDepartmentDiv").hide();
            }
          });
          //物料类别性质
          admin.getDictList("productTypeNature", "sys_product_type_nature", data ? data.productTypeNature : null, "物料类别性质");
          //物资类别
          admin.initDataSelectTree(
            true,
            "enterprise/product/admin/productType/getAllTreeData",
            { limit: 9999 },
            "selectProductType",
            data ? data.productTypeId : null,
            "物资类别",
            "productTypeId",
            null
          );
          //所属物资类别
          admin.initDataSelectTree(
            true,
            "enterprise/product/admin/productType/getAllTreeData",
            { limit: 9999 },
            "selectParentProductType",
            data ? data.parentProductType : null,
            "所属物资类别",
            "parentProductType",
            null
          );
          //类别维护部门
          admin.initDataSelectTree(
            true,
            "user/admin/role/getTreeData",
            null,
            "selectDepartment",
            data ? data.typeServiceDepartment : null,
            "类别维护部门",
            "typeServiceDepartment",
            null
          );
          //是否需要质检
          admin.getDictList("qualityIf", "sys_yes_no", data ? data.qualityIf : 1, "是否需要质检");
          form.on("select(qualityIf)", function (data) {
            if (data.value == 0) {
              $("#qualityRateDiv").show();
            } else if (data.value == 1) {
              $("#qualityRateDiv").hide();
            }
          });
          //检验频率
          // admin.getDictList(
          //   "qualityRate",
          //   "process_quality_rate",
          //   data ? data.qualityRate : null,
          //   "检验频率"
          // );
          //创建工序仓
          admin.getDictList("processWarehouseIf", "sys_yes_no", data ? data.processWarehouseIf : 1, "创建工序仓");

          form.on("select(processWarehouseIf)", function (data) {
            if (data.value == 0) {
              $("#thingCodeStatusDiv").show();
              $("#guaranteeStatusDiv").show();
              $("#inoutStatusDiv").show();
            } else if (data.value == 1) {
              $("#qualityRateDiv").hide();
              $("#guaranteeStatusDiv").hide();
              $("#inoutStatusDiv").hide();
            }
          });
          //是否一物一码
          admin.getDictList("thingCodeStatus", "sys_yes_no", data ? data.thingCodeStatus : null, "是否一物一码");
          //是否有质保期
          admin.getDictList("guaranteeStatus", "sys_yes_no", data ? data.guaranteeStatus : null, "是否有质保期");
          //是否先进先出
          admin.getDictList("inoutStatus", "sys_yes_no", data ? data.inoutStatus : null, "是否先进先出");

          form.val("processInfoForm", data);

          // 表单提交事件
          form.render("select");
          if (data) {
            var select = "dd[lay-value=" + data.departmentId + "]";
            $("select[name='departmentId']").siblings("div.layui-form-select").find("dl").find(select).click();
            /*var select = 'dd[lay-value=' + data.productTypeId + ']';
                        $("select[name='productTypeId']").siblings("div.layui-form-select").find('dl').find(select).click();*/

            $("#nodeTypes").val(data.nodeTypes);
            form.render("select");
          }
          form.on("submit(processInfoFormSubmit)", function (d) {
            // console.log(d.field);
            // return false;

            layer.load(2);
            admin.req(
              data ? "enterprise/product/admin/processInfo/update" : "enterprise/product/admin/processInfo/add",
              d.field,
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  table.reload("processInfoTable");
                  layer.closeAll("page");
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              data ? "PUT" : "POST"
            );
            return false;
          });
        }
      });
    }

    var processId = -1;
    var processName = "";

    //工序设备管理
    function showProcessDevice(data) {
      admin.open({
        type: 1,
        area: ["1500px", "85%"],
        title: "工序设备管理",
        content: $("#processDeviceForm").html(),
        success: function () {
          processId = data.id;
          processName = data.nodeNames;
          // 渲染表格
          var insTb = table.render({
            elem: "#processDeviceTable",
            url: config.base + "enterprise/product/admin/processDevice/list?processId=" + data.id,
            page: true,
            cellMinWidth: 80,
            // toolbar: '#toolbar',
            defaultToolbar: false,
            cols: [
              [
                // {type: 'checkbox'}
                // , {field: 'id', sort: true, title: 'ID'}
                { type: "checkbox" },
                //,{type: 'numbers',  title: '序号'}
                {
                  field: "deviceModelName",
                  align: "center",
                  title: "设备型号"
                },
                { field: "deviceCode", align: "center", title: "设备编码" },
                { field: "deviceTypeName", align: "center", title: "设备类型" },
                {
                  field: "deviceBrandName",
                  align: "center",
                  title: "设备品牌"
                },
                { field: "categoryName", align: "center", title: "所属分类" },
                { field: "workshopName", align: "center", title: "所属车间" },
                { field: "supplierName", align: "center", title: "供应商" },
                //, {field: 'description', title: '备注描述'}
                { field: "statusDesc", align: "center", title: "状态" },
                { field: "creatorName", align: "center", title: "录入人" },
                {
                  field: "createTime",
                  align: "center",
                  title: "添加时间",
                  width: 160
                },
                {
                  align: "center",
                  toolbar: "#processDeviceTableBar",
                  title: "操作"
                }
              ]
            ],
            done: function (res, curr, count) {}
          });

          // 工具条点击事件
          table.on("tool(processDeviceTable)", function (obj) {
            if (obj.event === "del") {
              // 删除
              processDeviceTableDelete(obj);
            }
          });

          // 添加按钮点击事件
          $("#processDeviceBtnAdd").click(function () {
            showDevice();
          });

          //生产设备列表
          function showDevice() {
            let deviceIndex = admin.open({
              type: 1,
              area: ["1480px", "80%"],
              title: "生产设备列表",
              content: $("#deviceForm").html(),
              success: function () {
                var insTb = table.render({
                  elem: "#deviceTable",
                  url: config.base + "enterprise/product/admin/processDevice/processList?processId=" + processId,
                  page: true,
                  cellMinWidth: 100,
                  // toolbar: '#toolbar',
                  defaultToolbar: false,
                  cols: [
                    [
                      { type: "checkbox" },
                      // , {field: 'id', sort: true, title: 'ID'}
                      { type: "numbers", align: "center", title: "序号" },
                      {
                        field: "deviceModelName",
                        align: "center",
                        title: "设备型号"
                      },
                      {
                        field: "deviceCode",
                        align: "center",
                        title: "设备编码"
                      },
                      {
                        field: "deviceTypeName",
                        align: "center",
                        title: "设备类型"
                      },
                      {
                        field: "deviceBrandName",
                        align: "center",
                        title: "设备品牌"
                      },
                      {
                        field: "categoryName",
                        align: "center",
                        title: "所属分类"
                      },
                      {
                        field: "workshopName",
                        align: "center",
                        title: "所属车间",
                        templet: (d) => (d.workshopName ? d.workshopName : "未选车间")
                      },
                      {
                        field: "supplierName",
                        align: "center",
                        title: "供应商"
                      },
                      { field: "statusDesc", align: "center", title: "状态" },
                      {
                        field: "creatorName",
                        align: "center",
                        title: "录入人"
                      },
                      {
                        field: "createTime",
                        align: "center",
                        title: "添加时间",
                        width: 160
                      }
                    ]
                  ],
                  done: function (res, curr, count) {}
                });
                form.on("submit(deviceTableSubmit)", function () {
                  let checkStatus = table.checkStatus("deviceTable").data;
                  var codes = [];
                  for (var i = 0; i < checkStatus.length; i++) {
                    codes.push(checkStatus[i].deviceCode);
                  }
                  admin.req(
                    "enterprise/product/admin/processDevice/add",
                    JSON.stringify({
                      processId: processId,
                      deviceCode: codes
                    }),
                    function (res) {
                      if (res.code == 200) {
                        layer.msg(res.msg, { icon: 1 });
                        table.reload("processDeviceTable");
                        layer.close(deviceIndex);
                      } else {
                        layer.msg(res.msg, { icon: 2 });
                      }
                    },
                    "POST",
                    true,
                    "application/json; charset=utf-8"
                  );
                });
              }
            });
          }

          // 批量刪除按钮点击事件
          $("#batchDelBtn").click(function () {
            let checkRows = table.checkStatus("processDeviceTable");
            if (checkRows.data.length == 0) {
              layer.msg("请选择要删除的数据", { icon: 2 });
            } else {
              new Promise((resolve, reject) => {
                let ids = "";
                checkRows.data.forEach((item) => {
                  ids += item.id + ",";
                });
                resolve(ids.substr(0, ids.length - 1));
              }).then((rData) => {
                layer.load(2);
                admin.req(
                  "enterprise/product/admin/processDevice/delBatch",
                  { ids: rData.split(",") },
                  (res) => {
                    layer.closeAll("loading");
                    if (res.code == 200) {
                      layer.msg(res.msg, { icon: 1 });
                      table.reload("processDeviceTable");
                    } else {
                      layer.msg(res.msg, { icon: 2 });
                    }
                  },
                  "DELETE"
                );
              });
            }
          });
        }
      });
    }

    function showProcessQuality(data) {
      admin.open({
        type: 1,
        area: "1200px",
        offset: "65px",
        title: "质检参数设置",
        content: $("#processQualityForm").html(),
        success: function () {
          var insTb = table.render({
            elem: "#processQualityTable",
            url: config.base + "production/qualityTesting/admin/processQuality/list",
            page: true,
            cellMinWidth: 100,
            cols: [
              [
                ,
                //{type: 'checkbox'}
                { field: "productTypeName", title: "产品类型" },
                { field: "processName", title: "工序" },
                { field: "categoryName", title: "分类" },
                { field: "name", title: "参数名" },
                { field: "code", title: "识别码" },
                { field: "type", title: "展示类型" },
                { field: "createTime", title: "创建时间" },
                {
                  align: "center",
                  toolbar: "#processQualityTableBar",
                  title: "操作",
                  width: 200
                }
              ]
            ],
            done: function (res, curr, count) {
              // 添加按钮点击事件
              $("#processQualityBtnAdd").click(function () {
                showProcessQuality();
              });

              function showProcessQuality(data) {
                admin.open({
                  type: 1,
                  area: "760px",
                  offset: "65px",
                  title: "质检参数设置",
                  content: $("#processQualityAddForm").html(),
                  success: function () {
                    var treeData = [];
                    admin.req(
                      "enterprise/product/admin/processQualityCategory/getTreeData",
                      { limit: 9999 },
                      function (res) {
                        if (res.code == 200) {
                          treeData = res.data;
                        } else {
                          layer.msg("获取质量参数分类失败", {
                            icon: 2,
                            time: 1000
                          });
                        }
                      },
                      "GET",
                      false
                    );
                    /* admin.reqSync('enterprise/product/admin/productType/getAllKnife',{},function (res) {
                                             if (res.code == 200) {
                                                 $.each(res.data,function (index,item) {
                                                     $("#productTypeId").append(new Option(item.name,item.id));
                                                 })
                                                 form.render('select');
                                             }else{
                                                 layer.msg(res.msg, {icon: 2});
                                             }

                                         },'GET')*/

                    admin.reqSync(
                      "enterprise/product/admin/processInfo/list",
                      { limit: 9999 },
                      function (res) {
                        if (res.code == 200) {
                          console.log(res.data);
                          $.each(res.data, function (index, item) {
                            $("#processId").append(new Option(item.nodeNames, item.id));
                          });
                          form.render("select");
                        } else {
                          layer.msg(res.msg, { icon: 2 });
                        }
                      },
                      "GET"
                    );

                    xmSelect.render({
                      el: "#selectCategory",
                      model: { label: { type: "text" } },
                      radio: true,
                      clickClose: true,
                      filterable: true,
                      tree: {
                        show: true,
                        strict: false,
                        expandedKeys: [-1]
                      },
                      tips: "顶级分类",
                      height: "auto",
                      data() {
                        return treeData;
                      },
                      on: function (data) {
                        //被选中的select的id,如果没有 -1
                        let categoryId = data.arr.length > 0 ? data.change[0].value : -1;
                        $("input[name='categoryId']").val(categoryId);
                      }
                    });

                    form.val("processQualityForm", data);
                    // 表单提交事件
                    form.on("submit(processQualityFormSubmit)", function (d) {
                      layer.load(2);
                      admin.req(
                        data ? "production/qualityTesting/admin/processQuality/update" : "production/qualityTesting/admin/processQuality/add",
                        d.field,
                        function (res) {
                          layer.closeAll("loading");
                          if (res.code == 200) {
                            layer.msg(res.msg, { icon: 1 });
                            table.reload("processQualityTable");
                            layer.closeAll("page");
                          } else {
                            layer.msg(res.msg, { icon: 2 });
                          }
                        },
                        data ? "PUT" : "POST"
                      );
                      return false;
                    });
                  }
                });
              }
            }
          });
        }
      });
    }

    // 删除
    function doDelete(obj) {
      layer.confirm(
        "确定要删除吗？",
        {
          offset: "65px",
          skin: "layui-layer-admin"
        },
        function (i) {
          layer.close(i);
          layer.load(2);
          admin.req(
            "enterprise/product/admin/processInfo/" + obj.data.id,
            {},
            function (res) {
              layer.closeAll("loading");
              if (res.code == 200) {
                layer.msg(res.msg, { icon: 1 });
                obj.del();
              } else {
                layer.msg(res.msg, { icon: 2 });
              }
            },
            "DELETE"
          );
        }
      );
    }

    // 工序设备管理 删除
    function processDeviceTableDelete(obj) {
      layer.confirm(
        "确定要移除吗？",
        {
          offset: "65px",
          skin: "layui-layer-admin"
        },
        function (i) {
          layer.close(i);
          layer.load(2);
          admin.req(
            "enterprise/product/admin/processDevice/delete?processDeviceId=" + obj.data.id,
            {},
            function (res) {
              layer.closeAll("loading");
              if (res.code == 200) {
                layer.msg(res.msg, { icon: 1 });
                obj.del();
              } else {
                layer.msg(res.msg, { icon: 2 });
              }
            },
            "DELETE"
          );
        }
      );
    }
    form.on("switch(isDeleted)", function (obj) {
      if (obj.elem.checked) {
        enable(obj.value);
      } else {
        disable(obj.value);
      }
    });
    // 导入excel
    $("#processInfoBtnExport").click(function () {
      var checkRows = table.checkStatus("processInfoTable");
      if (checkRows.data.length == 0) {
        layer.msg("请选择要导出的数据", { icon: 2 });
      } else {
        table.exportFile(insTb.config.id, checkRows.data, "xls", "工序列表");
      }
    });

    // 下载模版
    $("#downloadTemplate").click(function () {
      window.location.href = config.base + "enterprise/product/admin/processInfo/template";
    });

    // 导入excel
    $("#uploaderInput").on("change", function (e) {
      layer.load(2);
      var formData = new FormData();
      var files = e.target.files;
      let that = $(this);
      formData.append("file", files[0]);
      formData.append("name", files[0].name); //这个地方可以传递多个参数
      $.ajax({
        url: config.base + "enterprise/product/admin/processInfo/importExcel",
        data: formData,
        headers: { Authorization: "Bearer " + config.getToken() },
        type: "POST",
        processData: false,
        contentType: false,
        success: function (res) {
          layer.closeAll("loading");
          if (res.code == 200) {
            layer.msg(res.msg, { icon: 1 });
            layer.closeAll("page");
            setTimeout((_) => {
              location.reload();
            }, 1000);
          } else {
            layer.msg(res.msg, { icon: 2 });
          }
          that.val("");
        }
      });
    });

    function showProcessItemModel(data) {
      admin.open({
        type: 1,
        area: ["1440px", "85%"],
        title: "检测项管理",
        content: $("#processItemForm").html(),
        success: function () {
          processId = data.id;
          processName = data.nodeNames;
          // 渲染表格
          var insTb = table.render({
            elem: "#processItemTable",
            url: config.base + "enterprise/product/admin/productItem/list",
            where: {
              processId: data.id
            },
            page: true,
            cellMinWidth: 100,
            cols: [
              [
                { type: "numbers", title: "序号" },
                { field: "name", align: "center", title: "检测项目名称" },
                { field: "code", align: "center", title: "检测项目编码" },
                {
                  field: "itemCategoryName",
                  align: "center",
                  title: "所属检测分类"
                },
                { field: "itemTypeName", align: "center", title: "检测类型" },
                {
                  field: "qualityWayName",
                  align: "center",
                  title: "质检方法"
                },
                {
                  field: "deviceModelSpuName",
                  align: "center",
                  title: "质检器具"
                },
                // {
                //   field: "productTypeName",
                //   align: "center",
                //   title: "所属物资分类",
                // },
                // {
                //   field: "productNatureName",
                //   align: "center",
                //   title: "物资性质",
                // },

                {
                  field: "importanceName",
                  align: "center",
                  title: "重要程度"
                },
                {
                  field: "isDeleted",
                  align: "center",
                  title: "状态",
                  templet: function (d) {
                    if (d.isDeleted == true) {
                      return "禁用";
                    } else {
                      return "启用";
                    }
                  }
                },
                { field: "remark", align: "center", title: "描述" },

                { field: "createTime", align: "center", title: "创建时间" },
                {
                  align: "center",
                  toolbar: "#productItemTableBar",
                  title: "操作",
                  width: 200
                }
              ]
            ],
            done: function (res, curr, count) {
              //移除按钮
              var menuButton = config.getMenuButton(location.hash);
              // if (menuButton.indexOf("搜索") == -1) {
              //   $(".layui-form.toolbar").remove();
              // }
              // if (menuButton.indexOf("修改") == -1) {
              //   $("[lay-event='edit']").remove();
              // }
              // if (menuButton.indexOf("删除") == -1) {
              //   $("[lay-event='del']").remove();
              // }
            }
          });

          // 工具条点击事件
          table.on("tool(processItemTable)", function (obj) {
            var data = obj.data;
            if (obj.event === "editItem") {
              //修改
              data.eventType = "editItem";
              showEditItemModel(data);
            } else if (obj.event === "del") {
              // 删除
              doDelete(obj);
            }
          });

          function doDelete(obj) {
            layer.confirm(
              "确定要删除吗？",
              {
                offset: "65px",
                skin: "layui-layer-admin"
              },
              function (i) {
                layer.close(i);
                layer.load(2);
                admin.req(
                  "enterprise/product/admin/productItem/" + obj.data.id,
                  {},
                  function (res) {
                    layer.closeAll("loading");
                    if (res.code == 200) {
                      layer.msg(res.msg, { icon: 1 });
                      obj.del();
                      table.reload("processItemTable");
                    } else {
                      layer.msg(res.msg, { icon: 2 });
                    }
                  },
                  "DELETE"
                );
              }
            );
          }

          //监听排序
          table.on("sort(processItemTable)", function (obj) {
            table.reload("processItemTable", {
              initSort: obj,
              where: {
                sort: obj.field,
                order: obj.type
              }
            });
          });

          // 搜索
          form.on("submit(processItemSearchBtn)", function (data) {
            insTb.reload({ where: data.field, page: { curr: 1 } }, "data");
          });

          form.on("switch(isDeleted)", function (obj) {
            if (obj.elem.checked) {
              enable(obj.value);
            } else {
              disable(obj.value);
            }
          });

          function enable(id) {
            admin.req(
              "enterprise/product/admin/productAttribute/enable",
              { id: id },
              function (res) {
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  table.reload("productAttrTable");
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "GET"
            );
          }

          function disable(id) {
            admin.req(
              "enterprise/product/admin/productAttribute/disable",
              { id: id },
              function (res) {
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  table.reload("productAttrTable");
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "GET"
            );
          }

          // 添加按钮点击事件
          $("#processItemBtnAdd").click(function () {
            data.eventType = "addItemFromAttrTable";
            showEditItemModel(data);
          });

          $("#processItemCategoryBtnAdd").click(function () {
            data.eventType = "addItemFromAttrTable";
            showEditItemCategoryModel(data, undefined, "productItemCategoryForm", "productItemCategoryFormSubmit");
          });

          $("#productAttrBtnDel").click(function () {
            var checkRows = table.checkStatus("productAttrTable");
            if (checkRows.data.length == 0) {
              layer.msg("请选择要删除的数据", { icon: 2 });
            } else {
              var ids = "";
              checkRows.data.forEach((item) => {
                ids += item.id + ",";
              });
              delBatch(ids);
            }
          });

          function delBatch(ids) {
            admin.req(
              "enterprise/product/admin/productAttribute/delBatch",
              { ids: ids },
              function (res) {
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  table.reload("productAttrTable");
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "POST"
            );
          }
        }
      });
    }

    function showEditItemModel(data) {
      console.info(data, 9080);
      data.isDeleted = data.isDeleted == true ? "true" : "false";
      var openIndex = admin.open({
        type: 1,
        area: "700px",
        offset: "65px",
        title: data && (data.eventType == "addItem" || data.eventType == "addItemFromAttrTable") ? "添加物资检测项目" : "修改物资检测项目",
        content: $("#productItemForm").html(),
        success: async function () {
          console.log(123, processName);

          form.val("productItemForm", {
            processId: processId,
            processName: processName
          });

          //初始化物资分类
          admin.initDataSelect(
            "enterprise/product/admin/productType/list",
            { limit: 9999 },
            "productType",
            data.productTypeId != null ? data.productTypeId : data.productType,
            "物资分类",
            null,
            null
          );
          //初始化物资性质
          admin.getDictList("productNature", "sys_product_type_nature", data.productNature != null ? data.productNature : "7", "物资性质");

          //重要程度
          admin.getDictList("importanceCode", "pro_importance_type", data ? data.importanceCode : 1, "重要程度");

          // 设备型号 设备SPU  器具
          admin.req(
            "enterprise/device/admin/deviceModel/list",
            { page: 1, limit: 999 },
            function (res) {
              if (res.code == 200) {
                var html = '<option value="">请选择设备型号(设备SPU)</option>';
                for (var k = 0; k < res.data.length; k++) {
                  html += '<option value="' + res.data[k].id + '">' + res.data[k].name + "</option>";
                }
                $("form select[name='deviceModelSpuId']").html(html);
                form.render("select");
                if (data && data.deviceModelSpuId) {
                  form.val("productItemForm", data);
                }
              } else {
                layer.msg("获取设备编号(设备SKU)失败", { icon: 2, time: 1000 });
              }
            },
            "GET"
          );

          // 质检方法
          await admin.getDictListPro("qualityWayId", "sys_detection_method", "质检方法");
          // 质检方法

          // 质检类型
          await admin.getDictListPro("itemType", "sys_qc_quality_type", "质检类型");
          // admin.req(
          //   "production/quality/admin/qualityWay/list",
          //   { page: 1, limit: 999 },
          //   function (res) {
          //     if (res.code == 200) {
          //       var html = '<option value="">请选择质检方法</option>';
          //       for (var k = 0; k < res.data.length; k++) {
          //         html +=
          //           '<option value="' +
          //           res.data[k].id +
          //           '">' +
          //           res.data[k].qualityWayName +
          //           "</option>";
          //       }
          //       $("form select[name='qualityWayId']").html(html);
          //       form.render("select");
          //       if (data && data.qualityWayId) {
          //         form.val("productItemForm", data);
          //       }
          //     } else {
          //       layer.msg("获取质检方法失败", { icon: 2, time: 1000 });
          //     }
          //   },
          //   "GET"
          // );

          // //初始化检测类型
          // admin.getDictList("itemType", "sys_product_item_type", data.itemType, "检测类型");
          //初始化检测项目分类
          admin.initDataSelect(
            "production/qualityTesting/admin/qualityTestingCategory/list",
            // "enterprise/product/admin/productItemCategory/list",
            { limit: 9999, isDeleted: true },
            "itemCategoryId",
            data.itemCategoryId,
            "检测项目分类",
            null,
            null
          );

          //初始化样式
          // admin.getDictList(
          //   "style",
          //   "sys_product_item_style",
          //   data.style,
          //   "检测样式"
          // );

          if (data && data.eventType != "addItem" && data.eventType != "addItemFromAttrTable") {
            form.val("productItemForm", data);
            console.log(123, data);
          }

          var getTemplateHtml = function (i) {
            var labelName = "";
            var valLen = $("form input[name='value']").length;
            var classNew = "";
            if (valLen == 0) {
              labelName = "属性值";
            } else {
              classNew = "newAdd";
            }
            var templateHtml =
              "" +
              '<div class="attributeDiv layui-form-item ' +
              classNew +
              '" >' +
              '<div class="layui-form-item">' +
              "<div >" +
              '<label class="layui-form-label" >' +
              labelName +
              "</label>" +
              '<div class="layui-input-inline">' +
              '<input id="value' +
              i +
              '" name="value" placeholder="请输入属性" type="text" class="layui-input" lay-verify="required" required/>' +
              "</div>" +
              "</div>" +
              "<div >" +
              "</div>";
            templateHtml +=
              '<div class="layui-input-inline">' +
              '<button id="btnDel' +
              i +
              '" class="layui-btn delBtn" lay-filter="btnDel' +
              i +
              '" style="margin-left: 20px;">删除</button>' +
              "</div>";
            templateHtml += "</div>" + "</div>";
            return templateHtml;
          };

          var addTemplateDiv = function () {
            var html = getTemplateHtml(i++);
            $("#btnAddDiv2").prev().after(html);
            form.render();
            form.render("select");
            $(".delBtn")
              .off("click")
              .on("click", function () {
                var btn = $(this);
                var btnId = btn[0].id;
                var btnNo = btnId.substring("btnDel".length, btnId.length);
                btn.parent().parent().parent().remove();
              });
          };

          $("#btnAdd").click(addTemplateDiv);
          if (data && (data.eventType == "addItem" || data.eventType == "addItemFromAttrTable")) {
            $("#btnAdd").hide();
          }

          form.on("select(style)", function (data) {
            if (data.value == "text") {
              $("#btnAdd").hide();
              $(".attributeDiv").remove();
            } else if (data.value == "single") {
              $("#btnAdd").show();
              if ($("form input[name='value']").length == 0) {
                addTemplateDiv();
                $("#btnDel0").hide();
              }
            }
          });

          // 表单提交事件
          form.on("submit(productItemFormSubmit)", function (d) {
            layer.load(2);
            // var isDeleted = $("form input[name='isDeleted']").prop("checked");
            // if (!isDeleted) {
            //   d.field.isDeleted = false;
            // } else {
            //   d.field.isDeleted = true;
            // }

            admin.req(
              data && (data.eventType == "addItem" || data.eventType == "addItemFromAttrTable")
                ? "enterprise/product/admin/productItem/add"
                : "enterprise/product/admin/productItem/update",
              JSON.stringify(d.field),
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  if (data && (data.eventType == "addItemFromAttrTable" || data.eventType == "editItem")) {
                    table.reload("processItemTable");
                    layer.close(openIndex);
                  } else {
                    layer.closeAll("page");
                  }
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "POST",
              true,
              "application/json; charset=utf-8"
            );
            return false;
          });
        }
      });
    }

    function showEditItemCategoryModel(productTypeData, data, formId, submitButton, parentIdVal) {
      var openIndex = admin.open({
        type: 1,
        area: "440px",
        offset: "65px",
        title: "添加检测项目分类",
        content: $("#productItemCategoryForm").html(),
        success: function () {
          //初始化物资分类
          admin.initDataSelectTree(
            true,
            "enterprise/product/admin/productType/getTreeData",
            { limit: 9999 },
            "selectProductTypeQuery",
            productTypeData.productTypeId,
            "物资类别",
            "productType",
            null
          );
          //初始化物资性质
          admin.getDictList("productNature", "sys_product_type_nature", productTypeData.materialNature != null ? productTypeData.materialNature : "7", "物资性质");
          // //初始化检测类型
          // admin.getDictList("itemType", "sys_product_item_type", null, "检测类型");

          // 表单提交事件
          form.on("submit(" + submitButton + ")", function (d) {
            layer.load(2);
            var isDeleted = $("form input[name='isDeleted']").prop("checked");
            if (!isDeleted) {
              d.field.isDeleted = false;
            } else {
              d.field.isDeleted = true;
            }
            d.field.productType = productTypeData.id;
            admin.req(
              data ? "enterprise/product/admin/productItemCategory/update" : "enterprise/product/admin/productItemCategory/add",
              d.field,
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  layer.close(openIndex);
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              data ? "PUT" : "POST"
            );
            return false;
          });
        }
      });
    }
  });
</script>
